package crawler;

import java.util.ArrayList;
import java.util.List;

import asa.PostBucket;

import parser.ParserAnnotation;
import parser.ParserPipeline;

import forum.ForumFactory;
import forum.ForumPost;
import forum.ForumTag;

public class MockUpCrawler extends Crawler {

	private int crawled;

	public MockUpCrawler(ForumFactory fac, ParserPipeline pp, PostBucket bucket) {
		super("MockUp", fac, pp, bucket);
	}

	@Override
	public List<ForumPost> crawl() {
		List<ForumPost> ft = new ArrayList<ForumPost>();

		ForumPost fp1 = post("XXX",
				"Hi,\nHow to find the when was the Qlikview file last updated.");
		ForumPost fp2 = post("Nayan",
				"Hi\n\nTake one text box and apply the function"
						+ "\n\n='Last Updated at   : ' & ReloadTime()");
		ForumPost fp3 = post(
				"AshwinPagare",
				"Make variable :\n\nAt start tab of script level\n\n"
						+ "Let  LastDtReload=date(reloadtime(),'DD-MMM-YYYY');"
						+ "\n\nAt last tab of script level\n\nLet ENDTIME=now();\n\n"
						+ " and use this in text Object on you froent end to display it. as\n\n"
						+ "=LastDtReload & ENDTIME");
		ForumPost fp4 = post("andesh",
				"Detta är ett test för att utvärdera huruvida svenska kan hittas");
		ft.add(fp1);
		ft.add(fp2);
		ft.add(fp3);
		ft.add(fp4);
		crawled++;
		return ft;
	}

	private ForumPost post(String user, String body) {
		ParserAnnotation pa = pp.make(body);
		ArrayList<ForumTag> list = new ArrayList<ForumTag>();
		list.add(fac.makeTag("MockUpTag"));
		ForumPost fp1 = fac.makePost("Timestamp", pa, "Mockup", user,
				"2011-01-02", "00:00:00",
				"http://community.qlikview.com/forums/t/40951.aspx",
				"NoCategory", list);
		return fp1;
	}

	@Override
	public boolean canCrawl() {
		return crawled < 1;
	}

	@Override
	public void close() throws Exception {
	}
}
